import axios from '../../../utils/http'
import {baseURL} from '../../../utils/http'
import Cookies from 'js-cookie'

// 获取日历数据
export async function getDate(date) {
  const {
    data
  } = await axios.get('/bac/calendar', {
    params: {
      date: date
    }
  })
  return data
}

// 更新日历
export async function updateDate(id, remark, type) {
  const {
    data
  } = await axios.put('/bac/calendar', {
    id: id,
    remark: remark,
    type: type,
  })
  return data
}

// 添加导入Excel数据
export async function addExceldata(excelData) {
  const {
    data
  } = await axios.post('/bac/calendar/excelUpload', excelData)
  return data
}

export function downloadWorkShuttering() {
  fetch(baseURL+'/bac/calendar/downloadTemplate', {
    method: 'GET',
    headers: {
      'JHC-Authorization': Cookies.get('token')
    },
  }).then(res => {
    return res.blob()
  })
    .then(data => {
      const blobUrl = window.URL.createObjectURL(data)
      downloadWork(blobUrl)
    })
}

function downloadWork(blobUrl) {
  const a = document.createElement('a')
  a.download = '校历导入' + '.xlsx'
  a.href = blobUrl
  a.click()
}
